﻿using System;
using System.IO;
using Rsdn.SmartApp;

namespace Rsdn.Janus
{
    /// <summary>
    /// Редактор сообщений.
    /// </summary>
    public static class MessageEditor
    {
        /// <summary>
        /// Edits the message.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="msgInfo">The MSG info.</param>
        public static void EditMessage(
            IServiceProvider serviceProvider, 
            MessageFormMode mode, 
            MessageInfo msgInfo)
        {
            EditMessage(serviceProvider, mode, msgInfo, string.Empty, string.Empty);
        }

        /// <summary>
        /// Edits the message.
        /// </summary>
        /// <param name="serviceProvider">The service provider.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="msgInfo">The msg info.</param>
        /// <param name="editorText">My text.</param>
        /// <param name="autoSaveFileName"></param>
        public static void EditMessage(
            IServiceProvider serviceProvider,
            MessageFormMode mode,
            MessageInfo msgInfo,
            string editorText,
            string autoSaveFileName)
        {
            if (string.IsNullOrEmpty(autoSaveFileName))
            {
                // forget then could be duplicate file names
                autoSaveFileName = Path.GetRandomFileName();
                autoSaveFileName = autoSaveFileName.Replace(".", string.Empty);
            }

            MessageForm messageForm = new MessageForm(serviceProvider, mode, msgInfo, editorText, autoSaveFileName);
            messageForm.Show();

            if (mode == MessageFormMode.Edit)
            {
                IOutboxManager outboxManager = serviceProvider.GetRequiredService<IOutboxManager>();

                outboxManager.NewMessages.Refresh();
            }
        }
    }
}
/*
* 
 * Что нужно сохранять 
 * editorText
 * MessageFormMode mode, 
 * as MessageInfo
 * int forumId, 
 * int replyId, 
 * string subject, 
 * string msg
 */
